﻿varTeste = null;
function boneSystemTableController($scope, boneSystemStorage, ngTableParams, $filter, filterSettings) {
    $scope.firstPage = 1;
    $scope.countPerPage = 12;
    
    $scope.tableParams = new ngTableParams({
            page: $scope.firstPage,            // show first page
            count: $scope.countPerPage,           // count per page
            sorting: {
                id: 'asc'     // initial sorting
            },
            filter: {
                Descricao : ''
            }
            
    },
        {

        getData: function ($defer, params) {
            $scope.showLoadingPanel();
            boneSystemStorage.getList($scope.urlList, "")
                .success(function (data) {
                    if (!data.HasError) {
                        parent.varTeste = params.filter();
                        // Por enquanto o filtro é feito no lado cliente
                        var filterData = params.filter() ?
                           $filter('filter')(data.DataList, params.filter()) :
                           data.DataList;

                        // Ordena a lista e adiciona à variavel dataList do $scope
                        var orderList = params.sorting() ?
                                        $filter('orderBy')(filterData, params.orderBy()) :
                                        filterData;
                        
                        // update table params
                        params.total(orderList.length);
                        // set new data
                        $defer.resolve(orderList.slice((params.page() - 1) * params.count(), params.page() * params.count()));
                        
                        if (data.ShowMessage) {
                            MessageInformation(data.Message);
                        }
                        $scope.closeLoading();
                    } else {
                        $scope.$digest();
                        MessageError(data.Message);
                    }
                    $scope.closeLoading();
                });
        },
        total: 0
    });
}